package pacBiopackage;

import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;
import java.util.StringTokenizer;


public class PacBioProbTable
{
	private HashMap<Integer,HashMap<Integer,Double>> probTable;
	public PacBioProbTable(String filename)
	{
		this.probTable= new HashMap<Integer, HashMap<Integer,Double>>();
		fill_table(filename);
	}
	
	private void fill_table(String filename)
	{
		try 
		{
			BufferedReader br = new BufferedReader(new FileReader(filename));
			
			while(br.ready())
			{
				StringTokenizer token = new StringTokenizer(br.readLine()," ");
				Integer a = Integer.valueOf(token.nextToken());
				Integer b = Integer.valueOf(token.nextToken());
				Double c = Math.log(Double.valueOf(token.nextToken()));
				fillHashMap(this.probTable, a, b, c);
			}
		}
		catch (IOException e) 
		{
			e.printStackTrace();
		}
	}
	
	private void fillHashMap(HashMap<Integer, HashMap<Integer, Double>> map,Integer a, Integer b, Double c)
	{
		if(map.get(a) == null)
		{
			map.put(a,new HashMap<Integer, Double>());
		}
		if(map.get(a).get(b)==null)
		{
			map.get(a).put(b,c);
		}
	}

	public HashMap<Integer, HashMap<Integer, Double>> getProbTable() {
		return probTable;
	}

	public void setProbTable(HashMap<Integer, HashMap<Integer, Double>> probTable) {
		this.probTable = probTable;
	}
	
	public double getValue(Integer a,Integer b)
	{
		int a_v = (a%100)+1; //TODO hardcoded -> make it better!
		int b_v = (b%100)+1;
		return this.probTable.get(a_v).get(b_v);
	}
	
}
